<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AceCRC: /home/brian/src/AceCRC/src/ace_crc/crc16modbus_nibblem.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AceCRC
   &#160;<span id="projectnumber">1.1.1</span>
   </div>
   <div id="projectbrief">Cyclic Redundancy Check (CRC) algorithms (e.g. crc16ccitt, crc32) programmatically converted from C99 code generated by pycrc (https://pycrc.org) to Arduino C++ using namespaces and PROGMEM flash memory.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_7e2fca1243a23cea849d389c30292e19.html">ace_crc</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">crc16modbus_nibblem.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="crc16modbus__nibblem_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="crc16modbus__nibblem_8hpp.html">crc16modbus_nibblem.hpp</a>&quot;</span> <span class="comment">// header file converted by AceCRC</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">namespace </span>ace_crc {</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">namespace </span>crc16modbus_nibblem {</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="crc16ccitt__bit_8hpp.html#a5a452c1a176f3899bffa9a34fc6143bf">crc_t</a> crc_table[16] = {</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    0x0000, 0xcc01, 0xd801, 0x1400, 0xf001, 0x3c00, 0x2800, 0xe401,</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    0xa001, 0x6c00, 0x7800, 0xb401, 0x5000, 0x9c01, 0x8801, 0x4400</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;};</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160; </div>
<div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="crc16modbus__nibblem_8cpp.html#ad491a0feb68ee86c307ebf9450793d23">   38</a></span>&#160;<a class="code" href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">crc_t</a> crc_reflect(<a class="code" href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">crc_t</a> data, <span class="keywordtype">size_t</span> data_len)</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;{</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <a class="code" href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">crc_t</a> ret;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160; </div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    ret = data &amp; 0x01;</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="keywordflow">for</span> (i = 1; i &lt; data_len; i++) {</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        data &gt;&gt;= 1;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        ret = (ret &lt;&lt; 1) | (data &amp; 0x01);</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    <span class="keywordflow">return</span> ret;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;}</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160; </div>
<div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="crc16modbus__nibblem_8cpp.html#afa45be260a2a9b4024f7ba9b2a1ccada">   52</a></span>&#160;<a class="code" href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">crc_t</a> crc_update(<a class="code" href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">crc_t</a> crc, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> data_len)</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;{</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *d = (<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)data;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    uint8_t tbl_idx;</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="keywordflow">while</span> (data_len--) {</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        tbl_idx = crc ^ *d;</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        crc = crc_table[tbl_idx &amp; 0x0f] ^ (crc &gt;&gt; 4);</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        tbl_idx = crc ^ (*d &gt;&gt; 4);</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        crc = crc_table[tbl_idx &amp; 0x0f] ^ (crc &gt;&gt; 4);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;        d++;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    }</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keywordflow">return</span> crc &amp; 0xffff;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;}</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;} <span class="comment">// crc16modbus_nibblem</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;} <span class="comment">// ace_crc</span></div>
<div class="ttc" id="acrc16ccitt__bit_8hpp_html_a5a452c1a176f3899bffa9a34fc6143bf"><div class="ttname"><a href="crc16ccitt__bit_8hpp.html#a5a452c1a176f3899bffa9a34fc6143bf">ace_crc::crc16ccitt_bit::crc_t</a></div><div class="ttdeci">uint16_t crc_t</div><div class="ttdoc">The type of the CRC values.</div><div class="ttdef"><b>Definition:</b> <a href="crc16ccitt__bit_8hpp_source.html#l00068">crc16ccitt_bit.hpp:68</a></div></div>
<div class="ttc" id="acrc16modbus__nibblem_8hpp_html"><div class="ttname"><a href="crc16modbus__nibblem_8hpp.html">crc16modbus_nibblem.hpp</a></div><div class="ttdoc">Functions and types for CRC checks.</div></div>
<div class="ttc" id="acrc16modbus__nibblem_8hpp_html_a7df49a593b32380eb67639fecf3c9737"><div class="ttname"><a href="crc16modbus__nibblem_8hpp.html#a7df49a593b32380eb67639fecf3c9737">ace_crc::crc16modbus_nibblem::crc_t</a></div><div class="ttdeci">uint16_t crc_t</div><div class="ttdoc">The type of the CRC values.</div><div class="ttdef"><b>Definition:</b> <a href="crc16modbus__nibblem_8hpp_source.html#l00068">crc16modbus_nibblem.hpp:68</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
